#!/bin/sh
# rc.eibd -- Slackware startup script for eibd
# Start/stop/restart the eibd daemon.
# Written by V'yacheslav Stetskevych

# Run "eibd --help" to see all the various bus connection options.
# This script shows how to set up an IP Tunneling and USB connectios.
# Adapt to your needs.

eib_start() {
echo "Adding a multicast route for eibd..."
/sbin/route add 224.0.23.12 dev eth0

echo "Starting the eibd daemon..."
echo "$0: Startup error: first uncomment one of the startup options and remove this line."

## IP Tunnelling backend ================================================
## Use "eibnetsearch -" to locate your IP-capable BCU devices
#KNXIP="192.168.0.5"
#/usr/bin/eibd -DTS --daemon=/var/log/eibd.log --listen-tcp ipt:$KNXIP

## USB backend ==========================================================
#KNXUSB="$(findknxusb | awk '{print $2}' | grep -v addr)"
#/usr/bin/eibd -DTS --daemon=/var/log/eibd.log --listen-tcp usb:$KNXUSB

}

eib_stop() {
  echo "Deleting the eibd multicast route..."
  /sbin/route del 224.0.23.12
  echo "Stopping the eibd daemon..."
  killall eibd >/dev/null 2>&1
}

case $1 in
  start)  
    eib_start
   ;;
  stop)
    eib_stop
   ;;
  restart)
    eib_stop
    sleep 2
    eib_start
   ;;
  *) 
    echo "Usage: $0 {start|stop|restart}"
    exit 1
   ;;
esac 
